﻿namespace MVCSample.UI.Tests.Controllers
{
    using System.Web.Mvc;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class HomeControllerTest
    {
        private MVCSample.UI.Controllers.HomeController _controller;

        [TestInitialize]
        public void InitTest()
        {
            _controller = new MVCSample.UI.Controllers.HomeController();
        }

        [TestMethod]
        public void Web()
        {
            // Arrange
            ArrangeData();

            // Act
            var result = _controller.Web() as ViewResult;

            // Assert
            AssertCommon(result);
        }

        [TestMethod]
        public void Blog()
        {
            // Arrange
            ArrangeData();

            // Act
            var result = _controller.Blog() as ViewResult;

            // Assert
            AssertCommon(result);
        }

        [TestMethod]
        public void Book()
        {
            // Arrange
            ArrangeData();

            // Act
            var result = _controller.Book() as ViewResult;

            // Assert
            AssertCommon(result);
        }

        [TestMethod]
        public void Image()
        {
            // Arrange
            ArrangeData();

            // Act
            var result = _controller.Image() as ViewResult;

            // Assert
            AssertCommon(result);
        }

        [TestMethod]
        public void Local()
        {
            // Arrange
            ArrangeData();

            // Act
            var result = _controller.Local() as ViewResult;

            // Assert
            AssertCommon(result);
        }

        [TestMethod]
        public void News()
        {
            // Arrange
            ArrangeData();

            // Act
            var result = _controller.News() as ViewResult;

            // Assert
            AssertCommon(result);
        }

        [TestMethod]
        public void Patent()
        {
            // Arrange
            ArrangeData();

            // Act
            var result = _controller.Patent() as ViewResult;

            // Assert
            AssertCommon(result);
        }

        [TestMethod]
        public void Video()
        {
            // Arrange
            ArrangeData();

            // Act
            var result = _controller.Video() as ViewResult;

            // Assert
            AssertCommon(result);
        }

        private void ArrangeData()
        {
            // Do nothing
        }

        private void AssertCommon(ViewResult result)
        {
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.ViewData);
            Assert.IsNotNull(result.ViewData.Model);
        }

        [TestCleanup]
        public void EndTest()
        {
            if (_controller != null)
                _controller.Dispose();
        }
    }
}